package com.nuoniu.sibanyun.controller.cms;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.cms.CmsBanner;
import com.nuoniu.sibanyun.service.cms.ICmsBannerService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-08-10
 */
@RestController
@RequestMapping("/cms/banner")
@Api(tags = "横幅管理")
public class CmsBannerController extends BaseController {

    @Autowired
    private ICmsBannerService bannerService;

    @ApiOperation("获取列表")
    @GetMapping("list")
    public HttpResult list() {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("company_id", UserThreadLocal.get().getCompanyId());
        return HttpResult.ok(bannerService.list(wrapper));
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody CmsBanner banner) {
        banner.setCompanyId(UserThreadLocal.get().getCompanyId());
        bannerService.saveOrUpdate(banner);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        bannerService.removeById(id);
        return HttpResult.ok();
    }
}
